import {
  request,
  makePhoneCallHandler
} from '../../utils/requestUtils';
import { userBehavior } from '../../behaviors/userBehavior'

Page({
  behaviors: [userBehavior],
  // 页面的初始数据
  data: {
	goodsInfo: {}, // 商品详情
    count: 1, // 商品购买数量，默认是 1
    blessing: '' // 祝福语
  },

  //页面加载
  onLoad(option){
    this.getProductById(option.id);
  },
  // 加入购物车
  handleAddcart(e) {
    let component = this.selectComponent('#actionSheet')
    if (component) {
      component.addhow(e,this.data.goodsInfo);
    }
  },
  // 根据id查询商品
  async getProductById(id){
    console.log('查询商品',id)
    const result = await request({
      url: `/bus/customer/product/${id}`,
      method: "GET"
    })
    if(result.data.code==200){
      this.setData({
        goodsInfo:result.data.data
      })
    }
  },
    // 全屏预览图片
    previewImage() {
      wx.previewImage({
        urls: this.data.goodsInfo.detailsList.map(v=>v.url)
      })
    },
    // 联系商家
    async callMerchant(){
      console.log('this.data.goodsInfo', this.data.goodsInfo)
      let result = await makePhoneCallHandler(this.data.goodsInfo.stall.telephone)

    }
})
